package com.tico.translatereditor;

import com.tico.translatereditor.domain.TaskLinsten;
import com.tico.translatereditor.kafkaThread.KafkaChangeToipcThread;
import com.tico.translatereditor.kafkaThread.KafkaThread;
import com.tico.translatereditor.kafkaThread.ListenKafkaThread;
import com.tico.translatereditor.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class SpringListen implements ApplicationRunner {
    @Autowired
    private KafkaService kafkaService;
    @Autowired
    private KeyValuePairService keyValuePairService;
    @Autowired
    private TranslaterDataService translaterDataService;
    @Autowired
    private TaskLinstenService taskLinstenService;
    @Autowired
    private KafkaTopicService kafkaTopicService;
	@Override
	public void run(ApplicationArguments applicationArguments) throws Exception {
		try {
            //动态监听kafka改变
            new Thread(new KafkaThread(kafkaService,kafkaTopicService)).start();
            //启动默认侦听topic
            new Thread(new ListenKafkaThread(keyValuePairService,taskLinstenService)).start();
            //动态监听kafkaTopic改变
            new Thread(new KafkaChangeToipcThread(kafkaService,kafkaTopicService)).start();
		}catch (Exception e){
			log.error("启动异常",e);
			e.printStackTrace();
		}

	}
}